<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>输出重写用法</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="outcontrol.examples.basic.html">« 基本用法</a></li>
      <li style="float: right;"><a href="ref.outcontrol.html">Output Control 函数 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="outcontrol.examples.html">范例</a></li>
    <li>输出重写用法</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="outcontrol.examples.rewrite" class="section">
  <h2 class="title">输出重写用法</h2>
  <p class="para">
   自 PHP 7.1.0 起，<span class="function"><a href="function.output-add-rewrite-var.html" class="function">output_add_rewrite_var()</a></span>、<span class="function"><a href="function.output-reset-rewrite-vars.html" class="function">output_reset_rewrite_vars()</a></span>
   使用专用的输出缓冲区。即不使用 <a href="session.configuration.html#ini.session.use-trans-sid" class="link">trans sid</a> 输出缓冲区。
  </p>
  <p class="para">
   <div class="example" id="example-533">
    <p><strong>示例 #1 输出重写示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;此代码仅适用于&nbsp;PHP&nbsp;7.1.0、7.0.10、5.6.25&nbsp;及更高版本。<br /><br />//&nbsp;HTTP_HOST&nbsp;是默认目标主机。手动设置以使示例代码工作。<br /></span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_HOST'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">'php.net'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;输出重写仅重写表单。添加&nbsp;a=href.<br />//&nbsp;可以指定标签&nbsp;tag_name=url_attr,&nbsp;e.g.&nbsp;img=src,iframe=src<br />//&nbsp;设置间不允许有空格。<br />//&nbsp;表单标签是添加隐藏输入的特殊标签。<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'url_rewriter.tags'</span><span style="color: #007700">,</span><span style="color: #DD0000">'a=href,form='</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'url_rewriter.tags'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;added&nbsp;to&nbsp;URL&nbsp;and&nbsp;form<br /></span><span style="color: #0000BB">output_add_rewrite_var</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'value'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;<br /></span>&lt;a&nbsp;href="//php.net/index.php?bug=1234"&gt;bug1234&lt;/a&gt;<br />&lt;form&nbsp;action="https://php.net/?bug=1234&amp;edit=1"&nbsp;action="post"&gt;<br />&nbsp;&lt;input&nbsp;type="text"&nbsp;name="title"&nbsp;/&gt;<br />&lt;/form&gt;</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;a href=&quot;//php.net/?bug=1234&amp;test=value&quot;&gt;bug1234&lt;/a&gt;
&lt;form action=&quot;https://php.net/?bug=1234&amp;edit=1&quot; method=&quot;post&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;test&quot; value=&quot;value&quot; /&gt;
 &lt;input type=&quot;text&quot; name=&quot;title&quot; /&gt;
&lt;/form&gt;
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   自 PHP 7.1.0 起，输出重写函数有自己的 INI 设置：<a href="outcontrol.configuration.html#ini.url-rewriter.tags" class="link">url_rewriter.tags</a> 和 <a href="outcontrol.configuration.html#ini.url-rewriter.hosts" class="link">url_rewriter.hosts</a>。
  </p>
 </div></div></div></body></html>